﻿using System.Collections.Generic;
using System.Linq;
using Xunit;

namespace Gamemaster.RollTests
{
    public class d4Tests
    {
        [Fact]
        public void AverageIsCorrect()
        {
            List<int> results = RollManyTimes();

            double mean = results.Average();
            Assert.InRange(mean, 2, 3);
        }

        [Fact]
        public void RangeIsCorrect()
        {
            List<int> results = RollManyTimes();

            bool outOfRange = results.Any(r => r < 1 || r > 4);
            Assert.False(outOfRange);
        }

        [Fact]
        public void ProducesAtLeastOneOfEveryNumber()
        {
            List<int> actual = RollManyTimes();
            List<int> expected = new List<int>();

            for (int i = 1; i <= 4; i++)
            {
                expected.Add(i);
            }

            IEnumerable<int> notFound = expected.Except(actual);

            Assert.Empty(notFound);
        }

        List<int> RollManyTimes()
        {
            List<int> results = new List<int>();

            for (int i = 0; i < 1000; i++)
            {
                results.Add(Roll.d4());
            }

            return results;
        }
    }
}
